package com.sk.weichat.ui.account;

import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hlg.yueliao.wxapi.WXEntryActivity;
import com.sk.weichat.AppConstant;
import com.sk.weichat.BuildConfig;
import com.sk.weichat.MyApplication;
import com.sk.weichat.R;
import com.sk.weichat.Reporter;
import com.sk.weichat.adapter.MessageLogin;
import com.sk.weichat.bean.Code;
import com.sk.weichat.bean.ConfigBean;
import com.sk.weichat.bean.LoginRegisterResult;
import com.sk.weichat.helper.DialogHelper;
import com.sk.weichat.helper.LoginHelper;
import com.sk.weichat.helper.PrivacySettingHelper;
import com.sk.weichat.sp.UserSp;
import com.sk.weichat.ui.MainActivity;
import com.sk.weichat.ui.WebAgreementActivity;
import com.sk.weichat.ui.base.BaseActivity;
import com.sk.weichat.ui.base.CoreManager;
import com.sk.weichat.util.AppUtils;
import com.sk.weichat.util.Constants;
import com.sk.weichat.util.DeviceInfoUtil;
import com.sk.weichat.util.EventBusHelper;
import com.sk.weichat.util.PermissionUtil;
import com.sk.weichat.util.PreferenceUtils;
import com.sk.weichat.util.ToastUtil;
import com.tencent.connect.UserInfo;
import com.tencent.connect.auth.QQToken;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import com.xuan.xuanhttplibrary.okhttp.HttpUtils;
import com.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
import com.xuan.xuanhttplibrary.okhttp.result.ObjectResult;
import com.xuan.xuanhttplibrary.okhttp.result.Result;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;
import okhttp3.Call;

/**
 * 手机验证码登录界面
 */
public class SMSLoginActivity extends BaseActivity implements View.OnClickListener {

    private int mobilePrefix = 86;

    private String thirdToken;//第三方登录token

    private TextView tv_prefix, tvLoginPsw, tvUserAgreement, tvPrivacyPolicy;
    private EditText etPhoneNum;
    private ImageView ivClear, ivWXLogin, ivQQLogin;
    private Button btnSendSMS;

//    private Spinner spinner;

    private EditText etIp;

    private Button btnConnect;
    private Tencent mTencent;
    private BaseUiListener mIUiListener;
    private UserInfo mUserInfo;
    // private int mOldLoginStatus;

    public SMSLoginActivity() {
        noLoginRequired();
    }

    public void setThirdToken(String thirdToken) {
        this.thirdToken = thirdToken;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//暗色主题状态栏(白字)
            this.getWindow().getDecorView()
                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_VISIBLE);
        }
        setContentView(R.layout.activity_sms_login);
        getSupportActionBar().hide();

        //腾讯QQ登录初始化
        if (mTencent == null) {
            mTencent = Tencent.createInstance(Constants.QQ_APP_ID, this.getApplicationContext());
        }
//        mOldLoginStatus = MyApplication.getInstance().mUserStatus;
        thirdToken = getIntent().getStringExtra("thirdToken");
        tv_prefix = findViewById(R.id.tv_prefix);
        tv_prefix.setOnClickListener(this);
        etPhoneNum = findViewById(R.id.phone_num_sms_login);
        String phoneGet = getIntent().getStringExtra("phoneNum");
        if (TextUtils.isEmpty(phoneGet)) {
            phoneGet = UserSp.getInstance(mContext).getSavePhone("");
        }
        if (!TextUtils.isEmpty(phoneGet)) {
            if (phoneGet.length() == 11) {
                StringBuilder result = new StringBuilder();
                for (int i = 0; i < phoneGet.length(); i++) {
                    if (i == 3 || i == 7) {
                        result.append(" ");
                    }
                    result.append(phoneGet.charAt(i));
                }
                etPhoneNum.setText(result.toString());
                etPhoneNum.setSelection(result.toString().length());
            } else {
                etPhoneNum.setText(phoneGet);
                etPhoneNum.setSelection(phoneGet.length());
            }
        }
        ivClear = findViewById(R.id.iv_clear_text);
        ivClear.setOnClickListener(this);
        btnSendSMS = findViewById(R.id.btn_send_sms);
        btnSendSMS.setOnClickListener(this);
        tvLoginPsw = findViewById(R.id.tv_password_login);
        tvLoginPsw.setOnClickListener(this);
        ivWXLogin = findViewById(R.id.iv_wei_xin_login);
        ivWXLogin.setOnClickListener(this);
        ivQQLogin = findViewById(R.id.iv_qq_login);
        ivQQLogin.setOnClickListener(this);
        tvUserAgreement = findViewById(R.id.tv_user_agreement);
        tvUserAgreement.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goToWeb("悦聊用户协议", coreManager.getConfig().GET_USER_AGREEMENT);
            }
        });
        tvPrivacyPolicy = findViewById(R.id.tv_privacy_policy);
        tvPrivacyPolicy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goToWeb("悦聊隐私政策", coreManager.getConfig().GET_POLICY);
            }
        });
        chinaNumInput();
        permissionRequest();


        etIp = findViewById(R.id.et_ip_input);
        btnConnect = findViewById(R.id.btn_connect);
        btnConnect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                String strIp = "http://" + etIp.getText().toString().replace(" ", "") + ":8092/config";
                if (TextUtils.isEmpty(etIp.getText().toString())){
                    ToastUtil.showToast(SMSLoginActivity.this,"请填写域名");
                    return;
                }
                String strIp;
                if (!etIp.getText().toString().contains("http")){
                     strIp = "http://" + etIp.getText().toString().replace(" ", "") + ":8092/config";
                }else {
                     strIp = etIp.getText().toString().replace(" ", "");
                }
                Map<String, String> params = new HashMap<>();
                Reporter.putUserData("configUrl", strIp);
                DialogHelper.showMessageProgressDialog(SMSLoginActivity.this, "正在连接...");
                HttpUtils.get().url(strIp)
                        .params(params)
                        .build()
                        .execute(new BaseCallback<ConfigBean>(ConfigBean.class) {
                            @Override
                            public void onResponse(ObjectResult<ConfigBean> result) {
                                DialogHelper.dismissProgressDialog();
                                ConfigBean configBean;
                                if (result == null || result.getData() == null || result.getResultCode() != Result.CODE_SUCCESS) {
                                    Log.e("zq", "获取网络配置失败，使用已经保存了的配置");
                                    ToastUtil.showToast(mContext, "获取网络配置失败");
                                    if (BuildConfig.DEBUG) {
                                        ToastUtil.showToast(SMSLoginActivity.this, R.string.tip_get_config_failed);
                                    }
                                    // 获取网络配置失败，使用已经保存了的配置，
                                    configBean = coreManager.readConfigBean();
                                } else {
                                    Log.e("zq", "获取网络配置成功，使用服务端返回的配置并更新本地配置");
                                    ToastUtil.showToast(mContext, "获取网络配置成功");
                                    configBean = result.getData();
                                    if (!TextUtils.isEmpty(configBean.getAddress())) {
                                        PreferenceUtils.putString(SMSLoginActivity.this, AppConstant.EXTRA_CLUSTER_AREA, configBean.getAddress());
                                    }
                                    coreManager.saveConfigBean(configBean);
                                    MyApplication.IS_OPEN_CLUSTER = configBean.getIsOpenCluster() == 1 ? true : false;
                                }
                                setConfig(configBean);
                            }

                            @Override
                            public void onError(Call call, Exception e) {
                                DialogHelper.dismissProgressDialog();
                                Log.e("zq", "获取网络配置失败，使用已经保存了的配置");
                                ToastUtil.showToast(mContext, "获取网络配置失败");
                                // ToastUtil.showToast(SplashActivity.this, R.string.tip_get_config_failed);
                                // 获取网络配置失败，使用已经保存了的配置，
                                ConfigBean configBean = coreManager.readConfigBean();
                                setConfig(configBean);
                            }
                        });
            }
        });


        EventBusHelper.register(this);
    }

    private void setConfig(ConfigBean configBean) {
        if (configBean == null) {
            if (BuildConfig.DEBUG) {
                ToastUtil.showToast(this, R.string.tip_get_config_failed);
            }

            // 如果没有保存配置，也就是第一次使用，就连不上服务器，使用默认配置
            configBean = CoreManager.getDefaultConfig(this);
            if (configBean == null) {
                // 不可到达，本地assets一定要提供默认config,
                DialogHelper.tip(this, getString(R.string.tip_get_config_failed));
                return;
            }
            coreManager.saveConfigBean(configBean);
        }
    }

//    private void goToCode() {
//
//
//    }

    @Subscribe(threadMode = ThreadMode.MainThread)
    public void helloEventBus(MessageLogin message) {
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        //QQ授权成功后会回调
        if (requestCode == com.tencent.connect.common.Constants.REQUEST_LOGIN ||
                requestCode == com.tencent.connect.common.Constants.REQUEST_APPBAR) {
            Tencent.onActivityResultData(requestCode, resultCode, data, mIUiListener);
            return;
        }

        if (resultCode != SelectPrefixActivity.RESULT_MOBILE_PREFIX_SUCCESS)
            return;
        mobilePrefix = data.getIntExtra(Constants.MOBILE_PREFIX, 86);
        tv_prefix.setText("+" + mobilePrefix);
        etPhoneNum.setText("");
        if (mobilePrefix == 86) {
            etPhoneNum.setFilters(new InputFilter[]{new InputFilter.LengthFilter(13)});
        } else {
            etPhoneNum.setFilters(new InputFilter[]{new InputFilter.LengthFilter(11)});
        }
    }

    //输入号码格式监听
    private void chinaNumInput() {
        String inputStr = etPhoneNum.getText().toString();
        if (TextUtils.isEmpty(inputStr)) {
            ivClear.setVisibility(View.INVISIBLE);
            btnSendSMS.setTextColor(mContext.getResources().getColor(R.color.white));
            btnSendSMS.setBackgroundResource(R.drawable.bg_round_white_35);
        } else {
            ivClear.setVisibility(View.VISIBLE);
            btnSendSMS.setTextColor(mContext.getResources().getColor(R.color.deep_purple));
            btnSendSMS.setBackgroundResource(R.drawable.bg_round_white);
        }
        etPhoneNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s == null || s.length() == 0) {
                    ivClear.setVisibility(View.INVISIBLE);
                    btnSendSMS.setTextColor(mContext.getResources().getColor(R.color.white));
                    btnSendSMS.setBackgroundResource(R.drawable.bg_round_white_35);
                    return;
                }
                ivClear.setVisibility(View.VISIBLE);
                StringBuilder sb = new StringBuilder(s.toString());
                if (mobilePrefix == 86) {//中国大陆号码时，号码 *** **** ****格式化
                    if (s.length() == 13) {
                        btnSendSMS.setTextColor(mContext.getResources().getColor(R.color.deep_purple));
                        btnSendSMS.setBackgroundResource(R.drawable.bg_round_white);
                    } else {
                        btnSendSMS.setTextColor(mContext.getResources().getColor(R.color.white));
                        btnSendSMS.setBackgroundResource(R.drawable.bg_round_white_35);
                    }
                    if (before == 0) { //上一次是add时
                        if (sb.length() == 3 || sb.length() == 8) {//自动追加空格
                            sb.append(' ');
                        }
                    }
                    if ((sb.length() == 4 || sb.length() == 9) && sb.charAt(sb.length() - 1) != ' ') {
                        sb.insert(sb.length() - 1, ' ');
                    }
                } else {
                    btnSendSMS.setTextColor(mContext.getResources().getColor(R.color.deep_purple));
                    btnSendSMS.setBackgroundResource(R.drawable.bg_round_white);
                }
                if (!sb.toString().equals(s.toString())) {
                    etPhoneNum.setText(sb.toString());
                    etPhoneNum.setSelection(sb.toString().length());
                }

            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
    }

    //请求短信读取权限
    private void permissionRequest() {
        boolean isReadContacts = PermissionUtil.checkSelfPermissions(this,
                new String[]{Manifest.permission.READ_SMS, Manifest.permission.RECEIVE_SMS});
        if (!isReadContacts) {
            PermissionUtil.requestPermissions(this, 0x02,
                    new String[]{Manifest.permission.READ_SMS, Manifest.permission.RECEIVE_SMS});
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_prefix:// 选择国家区号
                Intent intent = new Intent(SMSLoginActivity.this, SelectPrefixActivity.class);
                startActivityForResult(intent, SelectPrefixActivity.REQUEST_MOBILE_PREFIX_LOGIN);
                break;
            case R.id.btn_send_sms://发送验证码
                String str = etPhoneNum.getText().toString().replace(" ", "");
                if (TextUtils.isEmpty(str)) {
                    ToastUtil.showToast(mContext, getString(R.string.please_input_phone_number));
                    return;
                }
//                if (mobilePrefix == 86) {
//                    if (str.length() != 13 || !str.startsWith("1")) {
//                        ToastUtil.showToast(mContext, "请输入正确的中国大陆区域手机号码");
//                        return;
//                    }
//                }
                if (!AppUtils.isMobile(str)){//手机号正则匹配
                    ToastUtil.showToast(mContext, "请输入正确的手机号码");
                    return;
                }
                requestAuthCode();
                break;
            case R.id.iv_clear_text://号码 X 清除按钮
                etPhoneNum.setText("");
                break;
            case R.id.tv_password_login://密码登录
                Intent intent2 = new Intent(SMSLoginActivity.this, LoginActivity.class);
                intent2.putExtra("thirdTokenLogin", thirdToken);
                intent2.putExtra("phoneNum", etPhoneNum.getText().toString().replace(" ", ""));
                startActivity(intent2);
                overridePendingTransition(R.anim.up_show_anim, R.anim.up_out_anim);
//                finish();
                break;
            case R.id.iv_wei_xin_login://微信登录
                WXEntryActivity.wxLogin(this);
                break;
            case R.id.iv_qq_login://QQ登录
                if (AppUtils.isQQClientAvailable(getApplicationContext())) {//QQ是否可用
                    mIUiListener = new BaseUiListener();
                    //all表示获取所有权限
                    mTencent.login(SMSLoginActivity.this, "all", mIUiListener);
                } else {
                    ToastUtil.showToast(getApplicationContext(), "请确认手机是否安装QQ客户端");
                }

                break;
        }
    }

    private void goToWeb(String title, String url) {
        Intent intent = new Intent(SMSLoginActivity.this, WebAgreementActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("url", url);
        startActivity(intent);
    }

    /**
     * QQ登录授权回调
     */
    private class BaseUiListener implements IUiListener {

        @Override
        public void onComplete(Object response) {
            if (null == response) {
                ToastUtil.showToast(SMSLoginActivity.this, "登录失败");
                return;
            }
            JSONObject jsonResponse = (JSONObject) response;
            if (null != jsonResponse && jsonResponse.length() == 0) {
                ToastUtil.showToast(SMSLoginActivity.this, "登录失败");
                return;
            }
            doComplete((JSONObject) response);
        }

        protected void doComplete(JSONObject obj) {

            try {
                DialogHelper.showMessageProgressDialog(SMSLoginActivity.this, "正在登录...");
                String openID = obj.getString("openid");
                String accessToken = obj.getString("access_token");
                String expires = obj.getString("expires_in");
                mTencent.setOpenId(openID);
                mTencent.setAccessToken(accessToken, expires);
                QQToken qqToken = mTencent.getQQToken();
                mUserInfo = new UserInfo(getApplicationContext(), qqToken);
                mUserInfo.getUserInfo(new IUiListener() {
                    @Override
                    public void onComplete(Object response) {
                        //是一个json串response.tostring，直接使用gson解析就好
                        Log.e(TAG, "登录成功" + response.toString());
                        loginQQ(openID, response);

                    }

                    @Override
                    public void onError(UiError uiError) {
                        DialogHelper.dismissProgressDialog();
                        Log.e(TAG, "登录失败" + uiError.toString());
                    }

                    @Override
                    public void onCancel() {
                        DialogHelper.dismissProgressDialog();
                        Log.e(TAG, "登录取消");

                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(UiError e) {
            DialogHelper.dismissProgressDialog();
            ToastUtil.showToast(SMSLoginActivity.this, "登录失败");
        }

        @Override
        public void onCancel() {
            DialogHelper.dismissProgressDialog();
            ToastUtil.showToast(SMSLoginActivity.this, "登录取消");
        }
    }

    /**
     * QQ授权后请求服务器登录
     *
     * @param code     QQ授权返回的openId
     * @param response QQ登录返回的用户信息
     */
    private void loginQQ(String code, Object response) {

        JSONObject result = (JSONObject) response;
        Map<String, String> params = new HashMap<>();
        params.put("loginInfo", code);
        params.put("type", Constants.LOGIN_QQ);
        params.put("nickname", result.optString("nickname"));
        params.put("sex", result.optString("gender").equals("男") ? "1" : "0");
        params.put("imgurl", result.optString("figureurl_qq_2"));
        params.put("province", result.optString("province"));
        params.put("city", result.optString("city"));
        params.put("serial", DeviceInfoUtil.getDeviceId(mContext));
        params.put("model", DeviceInfoUtil.getModel());
        params.put("latitude", String.valueOf(MyApplication.getInstance().getBdLocationHelper().getLatitude()));
        params.put("longitude", String.valueOf(MyApplication.getInstance().getBdLocationHelper().getLongitude()));

        HttpUtils.get().url(coreManager.getConfig().THIRD_GET_LOGING)
                .params(params)
                .build()
                .execute(new BaseCallback<LoginRegisterResult>(LoginRegisterResult.class) {

                    @Override
                    public void onResponse(ObjectResult<LoginRegisterResult> result) {
                        DialogHelper.dismissProgressDialog();
                        if (Result.checkSuccess(getApplicationContext(), result)) {
                            Intent intent;
                            switch (result.getData().getStatus()) {

                                case 0: //0,未绑定手机号；
                                    intent = new Intent(getApplicationContext(), BandAndChangePhoneActivity.class);
                                    intent.putExtra("type", Constants.BAND_PHONE_QQ);
                                    intent.putExtra("loginType", Constants.LOGIN_QQ);
                                    intent.putExtra("openId", result.getData().getOpenId());
                                    intent.putExtra("nickname", result.getData().getNickName());
                                    intent.putExtra("sex", result.getData().getSex());
                                    intent.putExtra("imgurl", result.getData().getHeadImgUrl());
                                    startActivity(intent);
                                    break;

                                case 1://1，成功登录
                                    loginQQSuccess(result);
                                    break;

                                case 2://2,未完善个人信息；
                                    intent = new Intent(getApplicationContext(), RegisterUserBasicInfoActivity.class);
                                    intent.putExtra(RegisterActivity.EXTRA_AUTH_CODE, result.getData().getAreaCode());
                                    intent.putExtra(RegisterActivity.EXTRA_PHONE_NUMBER, result.getData().getTelephone());
                                    intent.putExtra(RegisterActivity.EXTRA_INVITE_CODE, "");
                                    intent.putExtra(RegisterActivity.EXTRA_PASSWORD, "");
                                    intent.putExtra("nickname", result.getData().getNickName());
                                    intent.putExtra("sex", result.getData().getSex());
                                    intent.putExtra("imgurl", result.getData().getHeadImgUrl());
                                    intent.putExtra("thirdToken", thirdToken);
                                    startActivity(intent);
                                    break;

                                case -1://-1，用户已被禁用；
                                    ToastUtil.showToast(SMSLoginActivity.this, "用户已被禁用");
                                    break;
                            }
                        } else {
                            ToastUtil.showToast(SMSLoginActivity.this, "登录失败");
                        }

                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        DialogHelper.dismissProgressDialog();

                    }
                });
    }

    /**
     * QQ登录成功（已经绑定手机和完善信息）
     *
     * @param result
     */
    private void loginQQSuccess(ObjectResult<LoginRegisterResult> result) {
        if (result.getData().getIsRegister() == 1) {
            boolean success = false;
            if (result.getResultCode() == com.sk.weichat.volley.Result.CODE_SUCCESS) {
                success = LoginHelper.setLoginUser(mContext, coreManager, "888", result.getData().getPassword(), result);// 设置登录用户信息
            }
            if (success) {
                MultiAccountHelper.onLoginSuccess(mContext, result.getData().getUserId());
                PreferenceUtils.putBoolean(this, Constants.LOGIN_CONFLICT, false);// 重置登录冲突记录
                LoginRegisterResult.Settings settings = result.getData().getSettings();
                MyApplication.getInstance().initPayPassword(result.getData().getUserId(), result.getData().getPayPassword());
                PrivacySettingHelper.setPrivacySettings(SMSLoginActivity.this, settings);
                // 登录成功
                LoginRegisterResult.Login login = result.getData().getLogin();
                if (login != null && login.getSerial() != null && login.getSerial().equals(DeviceInfoUtil.getDeviceId(mContext))
                        && MyApplication.getInstance().mUserStatus != LoginHelper.STATUS_USER_NO_UPDATE && MyApplication.getInstance().mUserStatus != LoginHelper.STATUS_NO_USER) {
                    // 如果Token没变，上次更新也是完整更新，那么直接进入Main程序
                    // 其他的登录地方都需进入DataDownloadActivity，在DataDownloadActivity里发送此广播
                    LoginHelper.broadcastLogin(SMSLoginActivity.this);
                    Intent intent = new Intent(SMSLoginActivity.this, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    // 否则，进入数据下载界面
                    startActivity(new Intent(SMSLoginActivity.this, DataDownloadActivity.class));
                }
                finish();
            } else {
                // 登录失败
                String message = TextUtils.isEmpty(result.getResultMsg()) ? getString(R.string.login_failed) : result.getResultMsg();
                ToastUtil.showToast(mContext, message);
            }
        }
    }

    /**
     * 请求验证码
     */
    private void requestAuthCode() {
        Map<String, String> params = new HashMap<>();
        String language = Locale.getDefault().getLanguage();
        params.put("language", language);
        params.put("type", "0");//0.登录  1.忘记密码
        params.put("areaCode", mobilePrefix + "");
        params.put("telephone", etPhoneNum.getText().toString().replace(" ", ""));
        DialogHelper.showMessageProgressDialog(this, "正在请求验证码...");
        HttpUtils.get().url(coreManager.getConfig().SEND_LOGIN_CODE)
                .params(params)
                .build()
                .execute(new BaseCallback<Code>(Code.class) {

                    @Override
                    public void onResponse(ObjectResult<Code> result) {
                        DialogHelper.dismissProgressDialog();
                        if (result.getResultCode() == 1) {
//                            ToastUtil.showToast(mContext, getString(R.string.verification_code_send_success));
                            Intent intent = new Intent(SMSLoginActivity.this, SMSCodeActivity.class);
                            intent.putExtra("phoneNum", etPhoneNum.getText().toString());
                            intent.putExtra("areaCode", mobilePrefix + "");
                            intent.putExtra("isLogin", "1");
                            intent.putExtra("type", "0");
                            startActivity(intent);
//                            goToCode();
                        } else {
                            String message = TextUtils.isEmpty(result.getResultMsg()) ? "验证码获取失败" : result.getResultMsg();
//                            ToastUtil.showToast(mContext, message);
                            Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                        DialogHelper.dismissProgressDialog();
                        ToastUtil.showNetError(mContext);
                    }
                });
    }

    @Override
    protected void onDestroy() {
        MultiAccountHelper.setAddAccountFlag(false);
        super.onDestroy();
    }
}
